home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / rlib.zip / RL_GETPA.PRG < prev    next >
Text File  |  1993-01-04  |  1KB  |  42 lines

  1. * Function: GETPARM
  2. * Author..: Richard Low
  3. * Syntax..: GETPARM( number, string )
  4. * Returns.: Specified portion of the given string, starting at the number-1
  5. *           comma until the next comma, or end of string.
  6. *           if no parameter is given or is an invalid type.
  7.  
  8. FUNCTION GETPARM
  9. PARAMETERS p_number, p_string
  10. PRIVATE f_string
  11.  
  12. *-- make sure a parameters are correct
  13. IF TYPE('p_number') + TYPE('p_string') != 'NC'
  14.    RETURN ('')
  15. ENDIF
  16.  
  17. *-- make working copy to ensure original parmater is not touched
  18. f_string = p_string
  19.  
  20. *-- find the text following the (nth - 1) comma if any
  21. FOR x = 1 TO p_number - 1
  22.    *-- strip off text preceding the comma
  23.    f_string = TRIM( SUBSTR(f_string, AT(",",f_string) + 1 ) )
  24. NEXT x
  25.  
  26. *-- if there is a comma in the string
  27. IF AT(",",f_string) > 0
  28.    *-- if it's the 1st character
  29.    IF SUBSTR(f_string,1,1) = ","
  30.       *-- return nothing
  31.       RETURN ('')
  32.    ELSE
  33.       *-- return everything up to the comma
  34.       RETURN (SUBSTR(f_string, 1, AT(",",f_string)-1 ))
  35.    ENDIF
  36. ELSE
  37.    *-- if no comma, just return the string itself
  38.    RETURN (f_string)
  39. ENDIF
  40.  
  41. RETURN ('')
  42.